package com.xiemingtian.navdemo


import android.os.Bundle
import android.support.v4.app.Fragment
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.Navigation
import kotlinx.android.synthetic.main.fragment_login.*


class LoginFragment : Fragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_login, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        button.setOnClickListener {
            if (TextUtils.isEmpty(phone.text.toString())){
                phone.error = "empty"
                return@setOnClickListener
            }
            else{
                phone.error = null
            }
            val activity = activity as MainActivity
            activity.setIsLogin(true,phone.text.toString())
            val data = Bundle()
            data.putString("name",phone.text.toString())
            Navigation.findNavController(it).navigate(R.id.action_loginFragment_to_homeFragment,data,Util.launchNavOpt)
        }
    }


}
